The named moments the engine calls into your object's code, from Create through Draw GUI.
An event is one .gbml file, named for the moment it runs: create.gbml, step.gbml, alarm_0.gbml, and so on. You never call an event yourself - the engine calls the one that exists, at the point in the frame its name promises, and simply skips it if you never wrote one. Writing no draw.gbml at all is not a special case to remember, either: an object with no Draw event just draws its own sprite automatically (Where the machine shows through).
When each event runs puts these in order, one frame at a time, and also says what happens, and in what order, when a room opens.
| Event | Runs |
|---|---|
| Create | once, when the instance is made, after its object's own settings are put on it |
| Destroy, Cleanup | once, at the end of the frame in which the instance was destroyed (it finishes that frame first); Cleanup also fires on a room change and on shutdown |
| Step Begin, Step, Step End | every frame, in that order, around movement and collisions - see The order of a frame |
| Alarm 0–Alarm 11 | the frame that alarm's countdown reaches 0 |
Collision with <object> | once per instance of that object (or of one of its children) currently overlapping, after every collision this frame has already been found |
Button Pressed / Held / Released <button> | on the GBA's own ten buttons |
| Draw Begin, Draw, Draw End | drawing, in world space |
| Draw GUI | drawing fixed to the screen, unaffected by the camera |
| Room Start, Room End, Game Start | room and game boundaries |
| Beyond Room, Hit Room Edge, Beyond View | every frame the instance is past the room's bounds, on the room's edge, or outside the camera's view |
| Inside View | once, the frame the instance comes into the camera's view |
| Animation End | the frame a sprite's last frame finishes playing |
| Path End | a path this instance was following just finished - see Rooms |
| User 0–User 15 | only when your own code calls event_call(userN)/event_call(ObjectName.userN), or a cutscene step does |
alarm[0] through alarm[11] (Objects and instances) are twelve independent countdown timers every instance already has. Setting one to a positive number of frames starts it; the engine itself subtracts 1 every Step automatically, and the moment one reaches exactly 0, that alarm's event runs once:
![alarm[0] counting down from 5 to 0, one Step at a time, then firing its event](../img/alarm-countdown-light.png)
![alarm[0] counting down from 5 to 0, one Step at a time, then firing its event](../img/alarm-countdown-dark.png)
// objects/obj_turret/create.gbml
fire_delay = 45;
alarm[0] = fire_delay;// objects/obj_turret/alarm_0.gbml
fire_bolt();
alarm[0] = fire_delay; // re-arm - an alarm does not repeat on its ownAn alarm that reaches 0 does not restart itself; re-arming it (as the last line above does) is an ordinary assignment, not a special keyword, which is exactly why it can be a different value every time - a turret that fires faster as a fight goes on just assigns a smaller fire_delay.
An alarm you set from an Alarm event counts from the next Step, whatever its number, and whoever's alarm it is. Every alarm of every instance counts down first, and then the ones that reached 0 run, one instance after another and lowest number first. So alarm[2] = 1; written inside Alarm 1's event makes Alarm 2 run one Step later, and alarm[2] = 5; runs it five Steps later, exactly as if Alarm 1 had been a Step event. An alarm you set in a different instance, as in with (other_object) { alarm[0] = 1; }, or in the Create event of an instance an Alarm event makes, counts the same way: from the next Step, whether that instance comes before yours in the Step's order or after it. A chain such as Alarm 0 setting Alarm 1 setting Alarm 2 takes exactly the Steps you wrote. If two alarms run in the same Step, an earlier one can cancel the later one by writing 0 into it, or start it over by writing a bigger number (or a 1), before its turn comes.
Every overlap for the current frame is found before any Collision event for that frame runs, so one instance's Collision event never sees a partially-updated picture of who is touching whom - by the time any of them fire, the full set for this frame is already decided. The order of a frame places this precisely among the other nine steps of a frame.
Two things follow from that, and both are worth knowing before you rely on a Collision event. The events run in a fixed order (objects in the order your project lists them, then one object's events in alphabetical order of the object each names), so when two objects each have an event for the other, both run and the one listed first goes first. And an instance destroyed earlier in the frame takes no more part in collisions for the rest of it: events that were waiting for it are skipped. Collision has the whole story, with examples.